package a66weding.com.jiehuntong.activity.home.hotel.shop;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.xutils.x;

import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.adapter.MyBaseAdapter;
import a66weding.com.jiehuntong.beans.HomeProductDetail;
import a66weding.com.jiehuntong.beans.HomeProductGuessLike;
import a66weding.com.jiehuntong.common.utils.ImageOptionsUtil;

/**
 * Created by admin on 2016/9/13.
 */
public class TuWenGridAdapter extends MyBaseAdapter {

    public TuWenGridAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView==null){
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_home_detail_content_griditem,null);
            viewHolder.tv_gridname  = (TextView) convertView.findViewById(R.id.tv_gridname);
            viewHolder.tv_gridcollection = (TextView) convertView.findViewById(R.id.tv_gridcollection);
            viewHolder.tv_shopprice = (TextView) convertView.findViewById(R.id.tv_shopprice);
            viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            viewHolder.iv_gridlable = (ImageView) convertView.findViewById(R.id.iv_gridlable);
            viewHolder.ll_home_left_pager = (LinearLayout) convertView.findViewById(R.id.ll_home_left_pager);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        final HomeProductGuessLike.DataBean dataBean  = (HomeProductGuessLike.DataBean) data.get(position);
        x.image().bind(viewHolder.iv_gridlable,dataBean.getNvc_PicMain(), ImageOptionsUtil.getOptins320_320());
        viewHolder.tv_gridname.setText(dataBean.getNvc_Name());
        viewHolder.tv_gridcollection.setText( dataBean.getI_Collections() + "人收藏");
        viewHolder.tv_shopprice.setText(" ￥" + dataBean.getDm_ShopPrice());
        viewHolder.tv_price.setText( " ￥" + dataBean.getDm_Price());
        viewHolder.tv_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        viewHolder.ll_home_left_pager.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, HomeProductdetailActivity.class);
                intent.putExtra("productId", dataBean.getI_Id());
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHolder{
        //店铺名称
        private TextView tv_gridname;
        //收藏数
        private TextView tv_gridcollection;
        //打折价
        private TextView tv_shopprice;
        //原价
        private TextView tv_price;
        //图片
        private ImageView iv_gridlable;
        //整个图片
        private LinearLayout ll_home_left_pager;
    }
}
